<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
<html>
<head>
<title>BUY and Sell order</title>
<script type="text/javascript">
$(document).ready(function() { 
	
	$(submit).click(function(event) { 
	var reqUrl=($("#orderType").val()=="BUY")?"./buyOrder":"./sellOrder";
	//var userId= ('<sec:authentication property="principal.username"/>').replace('&#32;',' ');
	
	$.ajax(
		  {
		  type: "POST",
		  url: reqUrl,
		  dataType: "json",
		  contentType: 'application/json',
		  
		  data: JSON.stringify({ "insname":$("#insname").val(),"symbol":$("#symbol").val(),"qt":$("#qt").val(),"ql":$("#ql").val(),"qw":$("#qw").val(),"price":$("#price").val(),"tp":$("#tp").val()}),
		  success: function(html) { 
		    alert(html);
		  }
		  
		});
	});
});
</script>
</head>
<body>

	<h2>Buy and Sell For User "
	<sec:authentication property="principal.username" />"
	</h2>
<select id="orderType">
  <option value="BUY">Buy</option>
  <option value="SELL">Sell</option>
</select> 
	<form id="orderForm" method="post" action="./buy">
		<table>
			<tr>
				<th align="center"></th>
				<th>Insname</th>
				<th>Symbol</th>
				<th>Qt</th>
				<th>Ql</th>
				<th>Qw</th>
				<th>Price</th>
				<th>Tp</th>
			</tr>

			<tr>
				<td align="center"></td>
				<td><input name="insname" id="insname" value="206803" /></td>
				<td><input name="symbol"  id="symbol"value="GOLD" /></td>
				<td><input name="qt" id="qt" value="6" /></td>
				<td><input name="ql" id="ql" value="6" /></td>
				<td><input name="qw" id="qw" value="2" /></td>
				<td><input name="price" id="price" value="48000" /></td>
				<td><input name="tp" id="tp" value="288000" /></td>
			</tr>

		</table>
		<br /> <input type="button" id="submit" value="Save" />
	</form>
	
</body>
</html>